/**
 * 注册
 * Created by chen on 2016/9/21.
 */
$(function(){
    $('#regFrom').validator({
        rules: {
            //自定义一个规则，用来代替remote（注意：要把$.ajax()返回出来）
            myRemote: function(element){
                return $.ajax({
                    url: checkURL,
                    type: 'post',
                    data: element.name +'='+ element.value,
                    dataType: 'json',
                    success: function(data){}
                });
            },
            myVerify: function(element){
                return $.ajax({
                    url: checkVerifyURL,
                    type: 'post',
                    data: element.name +'='+ element.value,
                    dataType: 'json',
                    success: function(data){}
                });
            }
        },
        fields: {
            'account': '账号:required; account; myRemote;',
            'pwd': '密码:required;',
            'pwded': '确认密码:required; match(pwd);',
            'uname': '昵称:required;',
            'verify': '验证码:required; verify; myVerify;',
        },
        valid: function(form){
            var load = layer.load(2, {time: 10*1000});
            $.ajax({
                url: sendUrl,
                type: 'post',
                data: $(form).serialize(),
                dataType: 'json',
                success: function(data){
                    layer.close(load);
                    if (data.status) {
                        layer.msg(data.msg,{'icon' : 6,'time' : 3000},function(){
                            window.location.href = data.url;
                        });
                    } else {
                        layer.msg(data.msg,{'icon' : 5,'time' : 3000});
                    }
                }
            });
        }
    });
});